/*
 * RendererArbol.java
 *
 * Created on 24 de noviembre de 2008, 18:04
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Controller;

import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeNode;

/**
 *
 * @author Jhon Anthony Alvarez Borja
 */
public class RendererArbol extends DefaultTreeCellRenderer{
    
    /** Creates a new instance of RendererArbol */
    ImageIcon columna;
    ImageIcon tabla;
    ImageIcon bd;
    /**
     * 
     */
    public RendererArbol() {
        columna = new ImageIcon("src/Source/files.png");
        tabla = new ImageIcon("src/Source/folder.png");
        bd = new ImageIcon("src/Source/database.png");
    }
    
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
    {                        
        super.getTreeCellRendererComponent(tree,value,selected,expanded,leaf,row,hasFocus);
        String val = value.toString();
        ImageIcon i;
        DefaultMutableTreeNode nodo = (DefaultMutableTreeNode)value;        
        if(nodo.getParent() !=null ){              
            TreeNode t = nodo.getParent();
            if(t!=null){
                if(!nodo.isLeaf()){
                    setIcon(tabla);
                }else {
                    setIcon(columna);
                }
            }
        }else
            setIcon(bd);
        return this;
    }     
}
